<?php
class Cron extends ModelBase
{
	private $tableName = 'cron';
	
	public static function getInstance(){
		return parent::instance(__CLASS__);
	}
	
	public function getCronInfo($id){
		$app = Yii::app()->db->createCommand()
		->select('*')
		->from($this->tableName)
		->where('id=:id', array('id'=>$id))
		->queryRow();
		return $app;
	}

	public function getCronCount($uid)
	{
		$where = ' 1 ';
		if ($uid) $where .=' and uid = '.$uid;
		$user = Yii::app()->db->createCommand()
			->select('count(*) as num')
			->from($this->tableName)
			->where($where)
			->queryRow();
		return $user;

	}
	
	public function getCronList($uid,$offset=0,$pageSize = 10){
		$app = Yii::app()->db->createCommand()->select('*')->from($this->tableName)->limit($pageSize,$offset);
		if ($uid)$app->where('uid = '.$uid);
		$app = $app->queryAll();
		return $app;
	}

	public function add($data){
		$ret = Yii::app()->db->createCommand()->insert($this->tableName,$data);
		return $ret;
	}

	public function modify($data,$id){
        $id = (int) $id;
		if(!$id){
			return false;
		}
		$ret = Yii::app()->db->createCommand()->update($this->tableName,$data,'id = '.$id);
		return $ret;
	}
}